<template>
  <div class="distributor-application views-container">
    <el-dialog :visible.sync="dialogVisibleImg" width="30%" custom-class="reset-pwd wlm-form-dialog dialog-table">
      <div class="wlm-form">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">驳回原因</span>
        </div>
        <p style="padding:20px;min-height:200px">{{openDialogText}}</p>
      </div>
    </el-dialog>
    <el-dialog @close="resetDialogFormData" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
      <div class="wlm-form" v-if="dialogTableVisible">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">审核</span>
        </div>
        <el-scrollbar wrap-class="scrollbar-wrapper">
          <div class="wlm-form-content">
            <div class="wlm-dialog-main">
              <div class="wlm-dialog-content">
                <el-form ref="userForm" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
                  <el-form-item label="审核状态" prop="name">
                    <el-radio-group v-model="formFormatData.formData.status">
                      <!-- <el-radio label="10">待审核</el-radio> -->
                      <el-radio label="1">审核通过</el-radio>
                      <el-radio label="2">驳回</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="原因" prop="merchantlog" v-if="formFormatData.formData.status=='2'">
                    <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" v-model.trim="formFormatData.formData.reason">
                    </el-input>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
        </el-scrollbar>
      </div>
      <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
        <el-button size="small" type="primary" @click="formFormatSubmit({ router: { type: 'replace', path:formFormatData.formData.status=='2'?'/application/leaderApplication': '/application/leaderManagementAdd',query:{reg_id}, code: 1 }})">确定</el-button>
      </footer>
    </el-dialog>
    <div class="wlm-table">
      <div class="wlm-table-header" style="margin-bottom:20px;">
        <div class="dashboard-header">
          <el-row :gutter="8">
            <el-col :span="8">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                <div class="item-title">申请总数</div>
                <div class="item-num">
                  <span>{{tableFormatData.leaderApplicationTable.otherData.sum_sh}}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                <div class="item-title">通过数量</div>
                <div class="item-num">
                  <span>{{tableFormatData.leaderApplicationTable.otherData.y_sh}}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="dashboard-header-item flex-col flex-justify-c flex-align-c ">
                <div class="item-title">驳回数量</div>
                <div class="item-num">
                  <span>{{tableFormatData.leaderApplicationTable.otherData.w_sh}}</span>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
      <div class="wlm-table-header">
        <el-form :model="tableFormatData.leaderApplicationTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
          <el-form-item label="" class="filter">
            <el-form-item label="姓名：" class="search">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.leaderApplicationTable.files.user_name" placeholder="请输入姓名" style="width:175px;"></el-input>
            </el-form-item>
            <el-form-item label="电话：" class="search">
              <el-input @keyup.enter.native="filesSerch" :minlength="11" v-model="tableFormatData.leaderApplicationTable.files.phone" placeholder="请输入电话" style="width:175px;"></el-input>
            </el-form-item>
            <el-form-item label="用户：" class="search">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.leaderApplicationTable.files.nickName" placeholder="请输入用户昵称" style="width:175px;"></el-input>
            </el-form-item>
          </el-form-item>
          <el-form-item label="" class="filter-btns">
            <el-button type="primary" @click="filesSerch">筛选</el-button>
            <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="wlm-table-content">
        <el-table :ref="tableFormatData.leaderApplicationTable.key" :data="tableFormatData.leaderApplicationTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
          <el-table-column type="selection" width="55" :selectable='selectable'>
          </el-table-column>
          <el-table-column  label="用户">
            <template slot-scope="scope">
              <div class="wlm-table-logos flex-row">
                <img class="logo " :src="!scope.row.avatarUrl?'https://devwe7.weliam.cn/addons/weliam_areashop/web/assets/store/img/default_avatar.png':scope.row.avatarUrl">
                <div class="inner-text scale-grow">
                  <div class="ellipsis" style="width:150px;">{{scope.row.nickName}}</div>
                  <!-- <div class="flex-row flex-align-c flex-justify-c">ID:{{scope.row.user_id}} -->
                   <div>{{scope.row.user_id}}</div>
                  <!-- </div> -->
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="user_name" label="姓名"></el-table-column>
          <el-table-column label="电话">
            <template slot-scope="scope">
              <span>{{scope.row.phone||'-'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="地址" width="200px">
            <template slot-scope="scope">
              <span>{{scope.row  | filerAddress}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="community" label="小区名称">
          </el-table-column>
          <el-table-column prop="status" label="审核状态">
            <template slot-scope="scope">
              <span>{{scope.row.status==1?'审核通过':scope.row.status==2?"驳回":'未审核'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="审核方式">
            <template slot-scope="scope">
              <span>{{scope.row.type==1?'需后台审核':'无需审核'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="申请时间"> </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div class="operation-group">
                <el-button v-if="scope.row.status==3" class="wlm-text" type="text" @click="newFunction({id:scope.row.id,toggle:'dialogTableVisible',noEdit:true}, scope.row.id)">审核</el-button>
                <p v-if="scope.row.status==1">-</p>
                <el-button v-if="scope.row.status==2" class="wlm-text" type="text" @click="openDialog(scope.row.reason)">驳回原因</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-b flex-align-c">
          <el-row class="pagination-btns">
            <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.leaderApplicationTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
            <el-button class="right-8" type="primary" :disabled="isGroup" size="mini"  @click="auditBatch({redirect:'ids',id:'all',toggle:'dialogTableVisible',noEdit:true})">批量审核</el-button>
            <!-- <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button> -->
          </el-row>
          <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.leaderApplicationTable.pagination.page" :page-sizes="tableFormatData.leaderApplicationTable.pagination.pagesizes" :page-size.sync="tableFormatData.leaderApplicationTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.leaderApplicationTable.pagination.total : 0">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { leaderApplication, regsh } from '@/api/commityBuy'
import mixins from '@/mixins/mixins'
import Spa from './span'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'LeaderApplication',
  components: {
    Spa
  },
  data() {
    return {
      reg_id: 0,
      categoryData: {},
      dialogVisibleImg: false,
      dialogTableVisible: false,
      openDialogText: '',
      disabelsRow: [],
      tableFormatData: {
        current: 'leaderApplicationTable',
        leaderApplicationTable: {
          key: 'leaderApplicationTable',
          api: {
            getList: leaderApplication,
            delList: 1
          },
          tableData: [],
          files: {
            user_name: '',
            nickName: '',
            phone: '',
            ids: [],
            checkall: '0',
            Recycle: '1',
            redirect: 'apply_id'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          },
          otherData: {

          }
        }
      },
      formFormatData: {
        key: 'userForm',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        files: {
          ids: []
        },
        api: {
          editForm: {
            api: regsh,
            params: {
              id: ''
            }
          },
          submitForm: regsh
        },
        formData: {
          id: [],
          reason: '',
          status: '1',
          reg_id: ''
        },
        rules: {

        }
      }
    }
  },
  filters: {
    filerAddress(value) {
      const detail = value.address.detail ? value.address.detail : ''
      const detail1 = value.detail ? value.detail : ''
      return `${detail}${detail1}`
    }
  },
  created() {
    console.log(this.tableFormatData.leaderApplicationTable)
  },
  methods: {
    selectable(row, index) {
      let status = true
      if (row.status == 1) {
        status = false
        this.disabelsRow.indexOf(row) < 0 && this.disabelsRow.push(row)
      }
      return status
    },
    newFunction(params, id) {
      this.formFormatDialogEditEvt(params)
      this.formFormatData.formData.id = [id]
    },
    openDialog(params) {
      this.openDialogText = params
      this.dialogVisibleImg = true
    },
    auditBatch(params) {
      this.formFormatDialogEditEvt(params)
      var array = []
      this.tableFormatData.leaderApplicationTable.files.ids.map((item) => {
        array.push(item.id)
      })
      this.formFormatData.formData.id = array
    }
  }
}
</script>
